import redis

client = redis.StrictRedis(password='123456')
print(client)
# 设置数据
client.hset('student', 'name', '张三')
client.hsetnx('student', 'password', '123456')
client.hsetnx('student', 'name', '李四')
client.hsetnx('student', 'age', 20)
# 获取数据
r = client.hget('student', 'name')
print(r.decode())
# 获取所有的键值对
rs = client.hgetall('student')
print(rs)
# 获取所有的键
r = client.hkeys('student')
print(r)
# 获取所有的值
r = client.hvals('student')
print(r)
# 获取所有键的总数
r = client.hlen('student')
print(r)
# 判断指定的键是否存在
r = client.hexists('student', 'name')
print(r)
# 根据键删除
r = client.hdel('student', 'name')
print(r)
# age：自动增长
r = client.hincrby('student', 'age', 1)
print(r)

r = client.hdel('student', 'age')

# 释放资源
client.close()
